package com.zyf.project.binaryproto.encoder;

import com.zyf.project.binaryproto.specification.BinarySliceSpecification;
import utils.binary.BytesSlices;
import utils.binary.io.BytesInputStream;
import utils.binary.io.BytesOutputBuffer;

/**
 * <h1>分段编码器</h1>
 *
 * @author Zhou Yifan
 */
public interface SliceEncoder {

    /**
     * 获取格式标准
     *
     * @return {@link BinarySliceSpecification}
     */
    BinarySliceSpecification getSliceSpecification();

    /**
     * 将数据序列化到指定缓存中
     *
     * @param dataContract 数据
     * @param buffer       指定缓存 {@link BytesOutputBuffer}
     * @return 写入的字节数
     */
    int encode(Object dataContract, BytesOutputBuffer buffer);

    /**
     * 将 BytesInputStream 反序列化成数据片
     *
     * @param bytesInputStream {@link BytesInputStream}
     * @return {@link BytesSlices}
     */
    BytesSlices decode(BytesInputStream bytesInputStream);
}
